package com.rbt;

import com.avl.AVLTree;

import java.util.ArrayList;
import java.util.Random;

/**
 * 红黑树 与 AVL 树测试 添加顺序的元素
 */
public class PerformanceTest03 {

    public static void main(String[] args) {
        int  n = 20000000;
        Random random = new Random();
        ArrayList<Integer> testData = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            testData.add(i);
        }

        // test avl
        long startTime02 = System.nanoTime();
        AVLTree<Integer, Integer> avlTree = new AVLTree<>();
        for (Integer x: testData) {
            avlTree.add(x, null);
        }
        long endTime02 = System.nanoTime();
        double time02 = (endTime02 - startTime02) / 1000000000.0;
        System.out.println("AVL: " + time02 + " s");

        // test rbt
        long startTime03 = System.nanoTime();
        RBTree<Integer, Integer> rbTree = new RBTree<>();
        for (Integer x: testData) {
            rbTree.add(x, null);
        }
        long endTime03 = System.nanoTime();
        double time03 = (endTime03 - startTime03) / 1000000000.0;
        System.out.println("RBT: " + time03 + " s");
    }
}
